package it.tukano.fun;

/**
 * Checks if an instance is of some type
 * @author pgi
 */
public class InstanceOf implements Function1<Object, Boolean> {

    private final Class<?> TYPE;

    /**
     * Instance initializer
     * @param type the type to use in the check
     */
    public InstanceOf(Class<?> type) {
        TYPE = type;
    }

    /**
     * Checks if the given instance is compatible with the type used in the
     * constructor
     * @param p the instance to check
     * @return true if p != null && TYPE.isAssignableFrom(p.getClass())
     */
    public Boolean apply(Object p) {
        return p != null && TYPE.isAssignableFrom(p.getClass());
    }
}
